package com.lc.baseres.base;

import android.app.Application;
import android.support.annotation.Nullable;

import com.alibaba.android.arouter.launcher.ARouter;
import com.lc.baselib.net.intercept.GlobalHttpHandler;
import com.lc.baseres.dagger.component.AppComponent;
import com.lc.baseres.dagger.component.DaggerAppComponent;
import com.lc.baseres.dagger.module.AppModule;
import com.lc.baseres.dagger.module.ClientModule;

/**
 * @author LiuChao
 * @describe
 * @date 2018/6/21
 * @contact email:450127106@qq.com
 */
public abstract class BaseApplication extends Application {
    private static BaseApplication mAppCotext;
    private static AppComponent appComponent;

    @Override
    public void onCreate() {
        super.onCreate();
        appComponent = DaggerAppComponent.builder()
                .appModule(new AppModule(this))
                .clientModule(new ClientModule(getBaseUrl(), getGlobalHttpHandler()))
                .build();
        appComponent.inject(this);
        ARouter.openLog();
        ARouter.openDebug();
        ARouter.init(this);
        mAppCotext = this;
    }

    @Nullable
    public static Application getAppContext() {
        return mAppCotext;
    }

    public static AppComponent getAppComponent() {
        return appComponent;
    }

    abstract protected String getBaseUrl();

    abstract protected GlobalHttpHandler getGlobalHttpHandler();

}
